package leetcode_901_1000;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LeeCode_970 {
    public static void main(String[] args) {
        System.out.println(powerfulIntegers(2, 3, 10));
    }

    private static List<Integer> powerfulIntegers(int x, int y, int bound) {
        List<Integer> ans = new ArrayList<>();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < 1000; i++) {
            for (int j = 0; j < 1000; j++) {
                int num = (int) (Math.pow(x, i) + Math.pow(y, j));
                if (num > bound)
                    break;
                if (set.contains(num)) {
                    continue;
                }
                ans.add(num);
                set.add(num);
            }
        }
        return ans;
    }
}
